package com.song.invoicing.controller;

import com.song.invoicing.pojo.Result;
import com.song.invoicing.pojo.dao.PurchaseRecord;
import com.song.invoicing.pojo.dto.PurchaseQueryDTO;
import com.song.invoicing.pojo.dto.PurchaseRecordUpdateStatusDTO;
import com.song.invoicing.service.PurchaseRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/purchase_record")
@RequiredArgsConstructor
public class PurchaseRecordController {

     private final PurchaseRecordService purchaseRecordService;
    @GetMapping("/getPurchaseRecords")
    public Result<Map<String,Object> > getPurchaseRecords(PurchaseQueryDTO purchaseQueryDTO) {
        return Result.success(purchaseRecordService.getPurchaseRecords(purchaseQueryDTO));
    }
    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody PurchaseRecordUpdateStatusDTO purchaseRecordUpdateStatusDTO) {
        purchaseRecordService.updateStatus(purchaseRecordUpdateStatusDTO);
        return Result.success();
    }
    @PostMapping("/addPurchaseRecord")
    public Result addPurchaseRecord(@RequestBody PurchaseRecord purchaseRecord) {
        purchaseRecordService.addPurchaseRecord(purchaseRecord);
        return Result.success();
    }
    @PostMapping("/updatePurchaseRecord")
    public Result updatePurchaseRecord(@RequestBody PurchaseRecord purchaseRecord) {
        purchaseRecordService.updatePurchaseRecord(purchaseRecord);
        return Result.success();
    }
}
